Skip to content

[16.0][FIX] website_sale_stock_available#1213

Closed
SuShanVoong wants to merge 2 commits into
OCA:16.0from
factorlibre:16.0-fix-website_sale_stock_available
Closed

[16.0][FIX] website_sale_stock_available#1213
SuShanVoong wants to merge 2 commits into
OCA:16.0from
factorlibre:16.0-fix-website_sale_stock_available

Conversation

@SuShanVoong

@SuShanVoong SuShanVoong commented May 18, 2026

Copy link
Copy Markdown

Description

It was identified that within the website_sale_stock_available module, when computing stock quantities for a recordset of multiple products with the website_sale_stock_available context flag enabled, the _compute_quantities_dict override iterated the recordset one product at a time, reading product.immediately_usable_qty on each single-record recordset.

Cases Covered with This Improvement

  • Rendering of /shop and /shop/category/... pages where multiple product cards are displayed and the stock cascade is evaluated for each one.
  • Any caller invoking _compute_quantities_dict on a multi-product recordset with website_sale_stock_available=True in context (for example bulk queries from API endpoints or batched reports).

Implemented Solution

  • The _compute_quantities_dict override has been refactored to invoke _compute_available_quantities once on the full recordset before iterating. This pre-warm populates the ORM cache for immediately_usable_qty for every product at once, so the subsequent per-record reads inside the loop hit the cache instead of re-triggering the compute and the underlying cascade.

  • The behavior is functionally equivalent: the returned free_qty for each product still equals its immediately_usable_qty, just as before. Only the number of times the cascade executes changes — from N+1 to a single invocation on the full recordset.

FL-666-8676

@OCA-git-bot OCA-git-bot added series:16.0 mod:website_sale_stock_available Module website_sale_stock_available labels May 18, 2026
@IVA-BO

IVA-BO commented May 19, 2026

Copy link
Copy Markdown

LGTM!

Replace the explicit _compute_available_quantities() call with a batch
read(["immediately_usable_qty"]) so the standard ORM prefetch path is
used instead of binding to a specific compute method.

Forward lot_id/owner_id/package_id/from_date/to_date to with_context()
so immediately_usable_qty is computed with the same parameters as the
super() result, preventing args/context incoherence.

Update test to spy on _compute_available_quantities and assert it is
invoked once for the whole recordset, addressing the prefetch question
raised in the upstream review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:website_sale_stock_available Module website_sale_stock_available series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants